package edu.fim.data.dao.factory;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import edu.fim.data.dao.ConsumerDAO;
import edu.fim.data.dao.FoodDAO;
import edu.fim.data.dao.MealDAO;
import edu.fim.data.dao.ScheduleDAO;

/**
 * The DaoFactory implements the Singleton Design Pattern, and is responsible
 * for instantiating all types of Data Access Objects. It also has a DataSource,
 * which is given to all DAOs during their creation.
 * 
 * @author Itikawa
 */
public class DAOFactory {

	private static final DAOFactory INSTANCE = new DAOFactory();

	private EntityManager entityManager;

	private DAOFactory() {
	}

	public static DAOFactory getInstance() {
		return INSTANCE;
	}
	
	public EntityTransaction getTransaction() {
		return entityManager.getTransaction();
	}

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public ConsumerDAO createConsumerDao() {
		return new ConsumerDAO(entityManager);
	}

	public FoodDAO createFoodDao() {
		return new FoodDAO(entityManager);
	}
	
	public MealDAO createMealDao() {
		return new MealDAO(entityManager);
	}

	public ScheduleDAO createScheduleDAO() {
		return new ScheduleDAO(entityManager);
	}
}